#include<bits/stdc++.h>
#define int long long
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Rof(i,a,b) for(int i=a;i>=b;--i)
#define rep(i,a) for(int i=1;i<=a;++i)
#define print(x) printf("%lld\n",(int)x)
#define prn(x) printf("%lld ",(int)x)
using namespace std;
const int N=2e6+5,Mod=998244353;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){f=(ch=='-'?-f:f);ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
int n,q;
int l[N],r[N];
signed main(){
	freopen("study.in","r",stdin);
	freopen("study.out","w",stdout);
	n=read(),q=read();
	For(i,1,n-1) l[i]=read(),r[i]=read()-1;
	while(q--){
		int op=read();
		if(op==1){
			int x=read();
			l[x]=read(),r[x]=read()-1;
		}
		else{
			int a=read(),b=read(),c=read(),d=read();
			int ans=0,op=1;
			//~ if(a>c) swap(a,c),swap(b,d),op=0;
			if(a<c){
				For(i,a,c-1){
					if(l[i]>b){
						b=l[i];
					}
					else if(r[i]<b){
						ans+=(b-(r[i]));
						b=r[i];
					}
					b++;
				}
				if(b>d){
					ans+=(b-d);
				}
				printf("%lld\n",ans);
			}
			else{
				Rof(i,a-1,c){
					if(l[i]>b){
						b=l[i];
					}
					else if(r[i]<b){
						ans+=(b-r[i]);
						b=r[i];
					}
					b++;
					//~ cout<<l[i]<<" "<<r[i]<<" "<<b<<endl;
				}
				if(b>d){
					ans+=(b-d);
				}
				printf("%lld\n",ans);
			}
		}
	}
	return 0;
}
//
/*5 5
3 5
4 8
2 6 
5 10 
2 5 3 1 10 
2 2 6 5 6 
1 3 4 6
2 3 3 4 3
2 4 5 1 5
 */
